package com.gonsin.ta.logic.parse.serialize;

import com.gonsin.ta.logic.parse.Chain;
import com.gonsin.ta.logic.parse.condition.Condition;
import com.gonsin.ta.logic.parse.condition.Executable;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class ChainSerial implements TaDeserializable {

    /**
     * 流程id
     */
    private String chainId;

    /**
     * 流程名字
     */
    private String chainName;

    /**
     * 流程源码
     */
    private String qlScript;

    /**
     * 流程具体执行内容
     */
    private List<ConditionSerial> conditionSerials;

    @Override
    public Executable toExecutable(DeserializeContext deserializeContext) {
        Chain chain = new Chain();
        chain.setChainName(this.getChainName());
        chain.setChainId(this.getChainId());
        chain.setChainName(this.getChainName());
        chain.setQlScript(this.getQlScript());
        chain.setConditionList(new ArrayList<>());
        for(ConditionSerial conditionSerial : this.getConditionSerials()){
            chain.getConditionList().add((Condition) conditionSerial.toExecutable(deserializeContext));
        }
        return chain;
    }
}
